package com.bibrApp.difu.fragment.send_mvp;

import android.content.Context;
import android.util.Log;

import com.bibrApp.difu.api.RetrofitNet;
import com.bibrApp.difu.base.BasePresenter;
import com.bibrApp.difu.fragment.account_mvp.IAccountView;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class SendPresenter extends BasePresenter<ISendView> {

    public SendPresenter(Context context, ISendView iView) {
        super(context, iView);
    }

    public void getBtcUtxo(String publicKey) {
        RetrofitNet.getInstance().getApi(true)
                .getBtcUtxo("btc",publicKey)
                .compose(getActivityLifecycleProvider().bindToLifecycle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(o -> {
                    if (o != null && o.size()>0) {
                        Log.d("dj","===utxo=="+o.size());
                        iView.successOfUtxo(o);
                    }
                },throwable -> {
                    Log.d("dj",throwable.getMessage());
                });

    }

    /**
     * 广播btc交易
     * @param hash 16进制字符串（交易hash）
     */
    public void broadcastBtcTx(String hash) {
        RetrofitNet.getInstance().getApi(true)
                .broadcastTx("btc",hash)
                .compose(getActivityLifecycleProvider().bindToLifecycle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(o -> {
                    Log.d("dj","===广播==="+o);
                },throwable -> {
                    Log.e("dj",throwable.getMessage());
                });

    }

}
